---
layout: "default"
title: "withExtendedLifetime"
description: "Swift documentation for 'withExtendedLifetime': Evaluate f(x) and return its result, ensuring that x is not
destroyed before f returns."
keywords: "withExtendedLifetime,func,swift,documentation"
root: "/v2.1"
---

<div class="declaration" id="func-withextendedlifetime-t-result_-t_-t-throws-result">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-withextendedlifetime-t-result_-t_-t-throws-result">func withExtendedLifetime&lt;T, Result&gt;(<wbr>_:<wbr> T,  _: T throws -&gt; Result)</a>
        
<div class="comment collapse" id="comment-func-withextendedlifetime-t-result_-t_-t-throws-result"><div class="p">
    <p>Evaluate <code>f(x)</code> and return its result, ensuring that <code>x</code> is not
destroyed before f returns.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func withExtendedLifetime&lt;T, Result&gt;(x: T, @noescape _ f: T throws -&gt; Result) rethrows -&gt; Result</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-withextendedlifetime-t-result_-t_-throws-result">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-withextendedlifetime-t-result_-t_-throws-result">func withExtendedLifetime&lt;T, Result&gt;(<wbr>_:<wbr> T,  _: () throws -&gt; Result)</a>
        
<div class="comment collapse" id="comment-func-withextendedlifetime-t-result_-t_-throws-result"><div class="p">
    <p>Evaluate <code>f()</code> and return its result, ensuring that <code>x</code> is not
destroyed before f returns.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func withExtendedLifetime&lt;T, Result&gt;(x: T, @noescape _ f: () throws -&gt; Result) rethrows -&gt; Result</code>
    
    
</div></div>
</div>
